package moo.stargalaxy_bungee.api;

import com.alibaba.fastjson.JSONObject;
import moo.stargalaxy_bungee.data.HttpUtil;

import java.util.Objects;
import java.util.UUID;

public class GalaxyAPI {
    // 默认调试时配置地址(这里无用)
    public static String url = "http://0.0.0.0:8888";
    // 默认调试时连接秘钥
    public static String key = "Password";

    //public static void main(String[] args) {
    //    System.out.println(getCrossServerFid("TMIOtn_1688824735.000001983_neL"));
    //    //System.out.println(getServerTemplates());
    //    //System.out.println(createServer(UUID.randomUUID(), "Moo", "CatServer-1", 99));
    //}

    public static JSONObject sendGet(String type){
        return HttpUtil.sendGet(url, type, "UTF-8", key);
    }

    // 子服请求跨服时，让蹦极跨服插件进行访问接口进行验证是否允许跨服
    // /fun_crossserverfid_normal&server_fid=<服务器识别码>
    public static JSONObject getCrossServerFid(String serverID){
        return sendGet("/fun_crossserverfid_normal?server_fid=" + serverID);
    }

    // 获取全部可用子服模板
    // /get_serevertemplates
    public static JSONObject getServerTemplates(){
        return sendGet("/get_serevertemplates");
    }

    //
    // 创建玩家专属私人子服
    public static JSONObject createServer(UUID uuid, String player, String server, int max){
       return sendGet("/fun_createserver?user_uuid="+ uuid + "&user_name=" + player + "&template_file=" + server + "&user_max_create=" + max);
    }

    // /fun_deleteserver?server_fid=<服务器识别码>
    // 删除子服
    public static JSONObject deleteServer(String server){
        return sendGet("/fun_deleteserver?server_fid=" + server);
    }

    // /fun_verifiuserserver?user_uuid=<玩家UUID>&server_fid=<服务器识别码>
    // 验证特定子服是否对应玩家
    public static JSONObject verifyUserServer(UUID uuid, String server){
        return sendGet("/fun_verifiuserserver?user_uuid=" + uuid + "&server_fid=" + server);
    }

    // /sub_fidrundatas_plugins?server_fid=<服务器识别码>&online_player=<在线人数>&max_player=<最大在线人数>&runtime_tps=<当前实时TPS>&joinlimit_tps=<限制低的进入TPS>
    // 【内置功能】插件循环向控制台提交当前服务器运行信息
    // 子服插件实时回馈运行数据
    public static JSONObject gitServerData(String server, String playerOnline, String maxPlayer, String tps, String limitLowTPS){
        return sendGet("/sub_fidrundatas_plugins?server_fid=" + server + "&online_player=" + playerOnline + "&max_player=" + maxPlayer + "&runtime_tps=" + tps + "&joinlimit_tps=" + limitLowTPS);
    }

    //通知控制台修改当前子服特定数据
    // /sub_fidedits_plugins?server_fid=<服务器识别码>&data_type=<数据项目>&data_record=<新数据内容>
    public static JSONObject gitFixServerSpecialData(String server, String dataType, Objects objects){
        return sendGet("/sub_fidedits_plugins?server_fid=" + server + "&data_type=" + dataType + "&data_record=" + objects);
    }
    // /get_userservers?user_uuid=<玩家UUID>
    // 获取玩家拥有的全部子服
    public static JSONObject getPlayerServer(UUID uuid){
        return sendGet("/get_userservers?user_uuid=" + uuid);
    }

    // /get_serverinfo?server_fid=<子服识别码>
    // 获取特定子服下全部数据
    public static JSONObject getServerInfo(String server){
        return sendGet("/get_serverinfo?server_fid=" + server);
    }


}
